package com.lh.controller;

import com.alibaba.fastjson2.JSON;
import com.lh.mapper.UserMapper;
import com.lh.vo.Test;
import com.lh.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: linghao
 * @since: 2022/7/21
 */
@RestController
public class TestController {

    @Autowired
    private UserMapper userMapper;

    @PostMapping("/testC23")
    public String testC23(@RequestParam("name") String name, @RequestBody Test test){
        return JSON.toJSONString(test)+name;
    }

    @PostMapping("/testC4/{name}")
    public String testC4(@PathVariable String name, @RequestBody Test test){
        return JSON.toJSONString(test)+name;
    }

    @PostMapping("/testC3")
    public String testC3(@RequestParam("name") String name){
        return "test "+name;
    }

    @PostMapping("/testC5")
    public String testC5(@RequestBody String name){
        return "test "+name;
    }

    @GetMapping ("/testC1/{name}")
    public String testC1(@PathVariable String name){
        return "test "+name;
    }

    @GetMapping ("/testC6/{name}/{test}/{test2}")
    public String testC6(@PathVariable String name,@PathVariable String test,@PathVariable String test2){
        return "test "+name+" "+test+" "+test2;
    }

    @GetMapping ("/testUser/{id}")
    public String testUser(@PathVariable String id){
        User user = userMapper.selectById(id);
        return "test "+JSON.toJSONString(user);
    }
}
